package dq.study.jvm;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dongqun
 * @date 2020/6/8 13:43
 */
public class OomTest {

    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(10000);
        new Thread(new Thread0(),"thread-0").start();
        new Thread(new Thread1(),"thread-1").start();
    }

    static class Thread0 implements Runnable {
        @Override
        public void run() {
            List<byte[]> bytes = new ArrayList<>();
            while (true) {
                bytes.add(new byte[1024]);
            }
        }
    }

    static class Thread1 implements Runnable {
        @Override
        public void run() {
            while (true) {
                try {
                    List<byte[]> bytes = new ArrayList<>();
                    bytes.add(new byte[1024]);
                    Thread.sleep(1000);
                    System.out.println("---------------------");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
